#include <bits/stdc++.h>
using namespace std;
int T,n,a[200005],fr=0,fb=0,ans=0,maxx=0;
void dfs(int d){
    if(d>n){
        maxx=max(maxx,ans);
        return;
    }
    int t;
    if(a[d]==fr) ans+=a[d];
    t=fr;
    fr=a[d];
    dfs(d+1);
    fr=t;
    if(a[d]==fr) ans-=a[d];
    if(a[d]==fb) ans+=a[d];
    t=fb;
    fb=a[d];
    dfs(d+1);
    fb=t;
    if(a[d]==fb) ans-=a[d];
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T!=0){
        T--;
        maxx=0;ans=0;
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        dfs(1);
        cout<<maxx<<endl;
    }
    return 0;
}
